package com.platform.service;

import com.platform.dao.ApiCircleMapper;
import com.platform.dao.ApiCircleResMapper;
import com.platform.dao.ApiResourceMapper;
import com.platform.entity.ApiCircleResVo;
import com.platform.entity.ApiCircleVo;
import com.platform.entity.ApiResourceVo;
import org.apache.commons.collections4.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Service接口
 *
 * @author zhurusen
 * @email 524227263@qq.com
 * @date 2018-05-14 23:16:55
 */
@Service
public class ApiCircleResService {
    @Autowired
    private ApiCircleResMapper apiCircleResMapper;
    @Autowired
    private ApiResourceMapper apiResourceMapper;

    public List<ApiCircleResVo> selectList(Map params) {
        return apiCircleResMapper.queryList(params);
    }

    public void saveRes(ApiCircleVo circleVo, String redIds) {
        String redArr[] = redIds.split(",");
        for (int i = 0; i < redArr.length; i++) {
            if (!redArr[i].trim().equals("")) {
                ApiResourceVo apiResourceVo = apiResourceMapper.queryObject(Long.valueOf(redArr[i]));

                ApiCircleResVo res = new ApiCircleResVo();
                res.setCreateTime(new Date());
                res.setCircleId(circleVo.getId());
                res.setUserId(circleVo.getUserId());
                if (apiResourceVo != null) {
                    res.setUrl(apiResourceVo.getUrl());
                }
                apiCircleResMapper.save(res);
            }
        }
    }
}
